<?php

namespace App\Http\Controllers\Note;

use App\Http\Controllers\Controller;
use App\Models\Note\TopicDoc;
use Illuminate\Http\Request;

class TopicDocController extends Controller
{
    public function index($id)
    {
        $obj = TopicDoc::with(['doc'])->where('tid', $id)->orderBy('sort', 'desc')->get();
        return $this->response($obj);
    }

    public function store(Request $request, TopicDoc $obj)
    {
        $all = $request->all();
        $obj->fill($all);
        $obj->save();
        return $this->response();
    }


    public function update($id, Request $request)
    {
        $obj = TopicDoc::where('id', $id)->first();
        $obj->update($request->all());
        return $this->response();
    }

    public function destroy($id)
    {
        $obj = TopicDoc::find($id);
        $obj->delete();
        return $this->response();
    }
}
